package com.example.handler;

import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import com.example.feignApi.ProductFeignApiWithSentinel;
import com.example.mall.Product;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @ClassName ProductCenterFeignApiWithSentinelFallbackFactory
 * @Description TODO
 * @Author: XMK
 * @Date: 2020/4/29 20:24
 * @Version: 1.0
 */
@Component
public class ProductCenterFeignApiWithSentinelFallbackFactory implements FallbackFactory<ProductFeignApiWithSentinel> {
    @Override
    public ProductFeignApiWithSentinel create(Throwable throwable) {
        return orderId -> {
            Product product = new Product();
            product.setId(0L);
            if (throwable instanceof FlowException) {
                product.setProductName("流控默认产品");
            } else {
                product.setProductName("降级默认产品");
            }
            return product;
        };
    }
}
